CREATE TABLE [dbo].[AFIDetail]
(
[LineItem] [int] NOT NULL IDENTITY(1, 1),
[AFICode] [nvarchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ProductCode] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Unit] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Quantity] [int] NULL,
[UnitCost] [decimal] (12, 2) NULL,
[CoverPeriodFrom] [datetime] NULL,
[CoverPeriodTo] [datetime] NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[AFIDetail] ADD
CONSTRAINT [FK_AFIDetail_Unit] FOREIGN KEY ([Unit]) REFERENCES [dbo].[UnitTable] ([UnitCode])
ALTER TABLE [dbo].[AFIDetail] ADD 
CONSTRAINT [PK_AFIDetail_1] PRIMARY KEY CLUSTERED  ([LineItem]) ON [PRIMARY]
ALTER TABLE [dbo].[AFIDetail] ADD
CONSTRAINT [FK_AFIDetail_Product] FOREIGN KEY ([ProductCode]) REFERENCES [dbo].[Product] ([ProductCode])

GO

ALTER TABLE [dbo].[AFIDetail] ADD CONSTRAINT [FK_AFIDetail_AFI] FOREIGN KEY ([AFICode]) REFERENCES [dbo].[AFI] ([AFICode])
GO
